Skip to content

[FLINK-40225][table] Reject trailing tokens in JSON functions - #28815

Open
VasShabu wants to merge 4 commits into
apache:masterfrom
VasShabu:jsonLeadingTokenBug
Open

[FLINK-40225][table] Reject trailing tokens in JSON functions#28815
VasShabu wants to merge 4 commits into
apache:masterfrom
VasShabu:jsonLeadingTokenBug

Conversation

@VasShabu

@VasShabu VasShabu commented Jul 24, 2026

Copy link
Copy Markdown

What is the purpose of the change

Fixed the bug which causes some invalid JSON elements being parsed correctly without issue.

Brief change log

(for example:)

  • Ensured that failing on leading token got enabled
  • Corrected the invalid JSON that was present in the JSON_UNQUOTE function

Verifying this change

Please make sure both new and modified tests in this PR follow the conventions for tests defined in our code quality guide.

This change added tests and can be verified as follows:
Some tests were added as this PR
./mvnw -o -pl flink-table/flink-table-planner -Dtest='JsonFunctionsITCase' -Dsurefire.failIfNoSpecifiedTests=false -Dcheckstyle.skip=true -Dspotless.check.skip=true -e -Drat.skip=true -Denforcer.skip=true test

  • SELECT 'true, false' IS JSON; // False
  • SELECT 'true sdfoishjdoifhfs' IS JSON; // False

Previously these functions returned true

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): (no)
  • The serializers: (no)
  • The runtime per-record code paths (performance sensitive): (yes)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
  • The S3 file system connector: (no)

Documentation

  • Does this pull request introduce a new feature? (no)
  • If yes, how is the feature documented? (not applicable)

@flinkbot

flinkbot commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

@gustavodemorais gustavodemorais left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @VasShabu. The fix sounds reasonable, added two small suggestions.

Also, some nits:

  • PR/commit title says "Leading token" but the fix is FAIL_ON_TRAILING_TOKENS - trailing invalid tokens. Rename it to something short but informative like: "[FLINK-40225][table] Reject trailing tokens in JSON functions"
  • Make sure to rebase your changes on top of master
  • Make sure the CI is green

.testResult(
$("f0").isJson(JsonType.OBJECT),
"f0 IS JSON OBJECT",
true,
BOOLEAN()));
BOOLEAN().notNull()),
TestSetSpec.forFunction(BuiltInFunctionDefinitions.IS_JSON)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the same mapper now affects every JSON function, could we add a trailing-garbage case for JSON_VALUE/JSON_QUERY/JSON_EXISTS as well (e.g. {"a":1} x)? Right now a future revert of the flag would only fail the IS JSON specs

.testResult(
$("f0").isJson(JsonType.OBJECT),
"f0 IS JSON OBJECT",
true,
BOOLEAN()));
BOOLEAN().notNull()),
TestSetSpec.forFunction(BuiltInFunctionDefinitions.IS_JSON)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have multiple TestSetSpec, but you could group them under one single TestSetSpec as the tests above do

Suggested change
TestSetSpec.forFunction(BuiltInFunctionDefinitions.IS_JSON)
TestSetSpec.forFunction(BuiltInFunctionDefinitions.IS_JSON)
.onFieldsWithData("{} dsfsd", "true randomGarbage", "null, randomGarbage")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good

@VasShabu VasShabu changed the title [FLINK-40225][table] Fixed the Leading token bug [FLINK-40225][table] Reject trailing tokens in JSON functions Jul 28, 2026
@VasShabu
VasShabu force-pushed the jsonLeadingTokenBug branch from 9045511 to 85eea99 Compare July 29, 2026 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants